<template>
	<view class="container">
		<view class="goods_list" v-if="result.length>0">
			<view class="goods_unit" v-for="(item,index) in result" :key="index" :id="item.goods_id" v-on:click="goods_detail">
				<image class="goods_unit_pic" :style="{height:pic_h}" mode="aspectFill" :src="url+item.imgurl"></image>
				<view class="goods_name">{{item.goods_name.substr(0,9)}}…</view>
				<!-- <view class="sub_goods_name">{{item.title.substr(0,11)}}…</view> -->
				<view class="goods_property">
					<view class="goods_price">￥{{item.price}}</view>
				</view>
				<view class="goods_property">
					<view class="old_price">原价：￥{{item.original}}</view>
					<view class="goods_cash">销量：{{item.sum}}</view>
				</view>
				<view class="goods_commsion" v-if="item.commission!=0">
					<view class="commission_name">佣金</view>
					<view class="commission_price">￥{{item.commission}}</view>
				</view>
			</view>
		</view>
	</view>
</template>
<style>
	page{background: #F5F5F5;}
	.nav{width:100%;padding-bottom: 20upx;display: flex;justify-content: flex-start;z-index: 999;
	      align-items: flex-end;position: fixed;top:0;left:0;background: #F4F4F4;}
	.navigation{width:95%;padding-left:5%;height: 50upx;font-size: 28upx;color: #333;text-align: center;display: flex;justify-content: flex-start;align-items: center;}
	.navigation image{width:35upx;height: 35upx;}
	.navigation view{font-size: 32upx;color: #333;text-align: center;margin-left:33%;}
	.nav_lh{width:100%;}
	.goods_list{width:94%;margin:10upx 3%;display: flex;justify-content: space-between;align-items: center;flex-wrap: wrap;}
	.goods_unit{width:48%;background: #FFFFFF;/* box-shadow: 0px 0px 6px #ccc; */margin:20upx 0;display: flex;border-radius: 10upx;overflow: hidden;
	            flex-direction: column;justify-content: space-between;align-items: flex-start;padding-bottom: 10upx;background: #FFFFFF;}
	.goods_unit_pic{width:100%;overflow:hidden;}
	.goods_name{width:96%;padding:0 2%;line-height: 40upx;font-size: 28upx;color: #282828;}
	.sub_goods_name{width:96%;padding:0 2%;line-height: 35upx;font-size: 26upx;color:#AAAAAA;}
	.goods_property{width:96%;padding:0 2%;display: flex;justify-content: space-between;align-items: center;height: 40upx;}
	.goods_price{font-size: 36upx;color: #f40601;}
	.old_price,.goods_cash{font-size: 24upx;color: #AAAAAA;}
	.old_price{text-decoration: line-through;}
	.goods_property image{width:50upx;height: 50upx;}
	.goods_commsion{margin-left:2%;width:55%;display: flex;justify-content: space-between;align-items: center;height: 40upx;border-radius:10upx;overflow: hidden;}
	.commission_name{width:50%;line-height: 40upx;height:40upx;font-size:28upx;background:#ef3d19;color: #ffffff;text-align: center;}
	.commission_price{width:50%;line-height: 40upx;height:40upx;font-size:26upx;background:#ffece8;color: #ef3d19;text-align: center;}
</style>
<script>
	export default{
		data(){
			return {
				pic_h:'',
				nav_h:'',
				nav_lh:'',
				result:[],
				sort:0,
				status:0,
				start:0,
				url: getApp().globalData.url,
				static:getApp().globalData.static
			}
		},
		onLoad(e) {
			var res = uni.getSystemInfoSync();
			this.nav_h  = res.statusBarHeight +35+ "px";
			this.nav_lh = res.statusBarHeight +45+ "px";
			this.pic_h = res.windowWidth*0.94*0.48+"px";
			this.sort   = parseInt(e.sort);
			const scene = decodeURIComponent(e.scene);
			var upid = uni.getStorageSync("upid");
			if(scene=="undefined"||scene==undefined)
			{
				if(upid=="" || upid==undefined || upid=="undefined")
				{
					if(e.upid==undefined)
					{
						uni.setStorageSync("upid",0);
					}
					else
					{
						uni.setStorageSync("upid",parseInt(e.upid));
					}
				}
			}
			else
			{
				uni.setStorageSync("upid",scene);
			}
		},
		onShow(){
			this.initialize();
		},
		onReachBottom:function()
		{
			this.status = 1;
			this.initialize();
		},
		methods:{
			reback:function()
			{
				uni.navigateBack();
			},
			goods_detail:function(e)
			{
				var id = e.currentTarget.id;
				uni.navigateTo({
					url:"../mall/goods_detail?id="+id
				})
			},
			initialize:function()
			{
				var that = this;
				var member_id = uni.getStorageSync("member_id");
				//#ifdef MP-WEIXIN
				var type = "weixin";
				//#endif
				//#ifdef APP-PLUS
				var type = "app";
				//#endif
				//#ifdef H5
				var type = "app";
				//#endif
				uni.request({
					url: that.url+'/wechat_goods_list', 
					data: {sort:this.sort,type:type,member_id:member_id,start:this.start},
					header: {'Content-Type': 'application/json'},
					success: (res) => {
						console.log(res);
						if(res.data.status==1)
						{
							that.start += 10;
							for(var i=0;i<res.data.result.length;i++)
							{
								that.result.push(res.data.result[i]);
							}
						}
					}
				})
			}
		}
	}
</script>
